import React from 'react';

import { Router } from 'dva/router';
const cached = {};

function registerModel(app, model) {
  console.log(app)
  if (!cached[model.namespace]) {
    app.model(model);

    cached[model.namespace] = 1;
  }
}
function RouterConfig({ history, app }) {
  const routes = [
    //配合登录
    {
      path: '/logins',
      name: 'Logins',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/logins'));
          cb(null, require('./routes/Logins'));
        });
      },
    },
    //后台管理登录
    {
      path: '/admin',
      name: 'Admin',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/video/video'));
          cb(null, require('./routes/Video/Video'));
        });
      },
    },
    // // 直播界面
    {
      path: '/playIndex',
      name: 'User',
      getComponent(nextState, cb) {

        require.ensure([], (require) => {
          registerModel(app, require('./models/user/user'));
          cb(null, require('./routes/User/User'));
        });
      },
    },
    // 直播界面
    {
      path: '/playLive',
      name: 'playLive',
      getComponent(nextState, cb) {

        require.ensure([], (require) => {
          registerModel(app, require('./models/playLive/playLive'));
          cb(null, require('./routes/PlayLive/playLive'));
        });
      },
    },


    // 官网主页
    // {
    //   path: '/',
    //   name: 'Home',
    //   getComponent(nextState, cb) {
    //     require.ensure([], (require) => {
    //       registerModel(app, require('./models/home/home'));
    //       cb(null, require('./routes/Home/Home'));
    //     });
    //   },
    // },

    // 官网主页
    {
      path: '/',
      name: 'Class',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/class/index'));
          cb(null, require('./routes/Class/Index'));
        });
      },
    },


    // 课程
    // {
    //   path: '/class',
    //   name: 'Home',
    //   getComponent(nextState, cb) {
    //     require.ensure([], (require) => {
    //       registerModel(app, require('./models/courseIndex/courseIndex'));
    //       cb(null, require('./routes/CourseIndex/courseIndex'));
    //     });
    //   },
    // },
    // 课程
    {
      path: '/classIndex',
      name: 'Home',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/class/index'));
          cb(null, require('./routes/Class/Index'));
        });
      },
    },




    //
    // // 后台管理
    // {
    //   path: '/manage',
    //   name: 'Manage',
    //   getComponent(nextState, cb) {
    //     require.ensure([], (require) => {
    //       registerModel(app, require('./models/manage/manage'));
    //       cb(null, require('./routes/Manage/Index'));
    //     });
    //   },
    // },

    // 更多
    {
      path: '/moreIndex',
      name: 'MoreIndex',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/moreCourse/moreIndex'));
          cb(null, require('./routes/MoreCourse/moreIndex'));
        });
      },
    },
    // 课程详情
    {
      path: '/courseDetail',
      name: 'CourseDetail',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/courseDetail/courseDetail'));
          cb(null, require('./routes/CourseDetail/courseDetail'));
        });
      },
    },
    // 我的课程
    {
      path: '/mycourse',
      name: 'Mycourse',
      getComponent(nextState, cb) {
        require.ensure([], (require) => {
          registerModel(app, require('./models/mycourse/mycourse'));
          cb(null, require('./routes/MyCourse/myCourse'));
        });
      },
    },

  ];

  return <Router history={history} routes={routes} />;
}
export default RouterConfig;
